<?php

namespace App\Morefun\Scratch;

use App\Contracts\Services\Storage\StorageService;
use App\Entities\Activity;
use App\Morefun\Activity\RedisSynchronizerBase;
use Illuminate\Container\Container;
use Illuminate\Support\Arr;

class RedisSynchronizer extends RedisSynchronizerBase
{
    public function write(Activity $activity)
    {
        if (null === $activity) {
            return;
        }

        $this->writeBasic($activity);
        $this->writeRules($activity);
    }

    public function writeBasic(Activity $activity)
    {
        $id = $activity->getAttribute('id');
        $translated = $this->translateActivitySummary($activity);

        $this->redis()->set(sprintf('scratch:%s', $id), \GuzzleHttp\json_encode($translated));
    }
}
